package com.winspread.app.hitl.room

import android.content.Context
import androidx.room.Room
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Named
import javax.inject.Singleton

/**
 *Author: Amin
 *Data: 2022/4/19 9:54
 *
 *Description:
 *
 */
@InstallIn(SingletonComponent::class)
@Module
object BookModule {

    @Provides
    @Singleton
    @Named(value = "BOOK")
    fun provideDatabase(@ApplicationContext appContext: Context): AppDataBase {
        return Room.databaseBuilder(
            appContext,
            AppDataBase::class.java,
            "book.db"
        ).build()
    }



    @Provides
    @Named("BOOK")
    fun provideBookDao(@Named("BOOK")dataBase: AppDataBase): BookDao {
        return dataBase.bookDao()
    }



    @Provides
    @Singleton
    @Named(value = "BOOKTEST")
    fun provideDatabaseTest(@ApplicationContext appContext: Context): AppDataBase {
        return Room.databaseBuilder(
            appContext,
            AppDataBase::class.java,
            "book_test.db"
        ).build()
    }


    @Provides
    @Named("BOOKTEST")
    fun provideBookDaoTest(@Named("BOOKTEST")dataBase: AppDataBase): BookDao {
        return dataBase.bookDao()
    }




}